﻿

function VoteSuccess(data) {
	if (data.error) {
		alert("You must be logged in to vote.");
		return;
	}

	if (!data.isReply) {
	    var button = $(".post .vote-" + (data.direction > 0 ? "up" : "down"));
	    var number = $(".post strong");
	    $(".post .vote-button a").removeClass("selected");
	    button.addClass("selected");
	    number.text(data.voteCount);
	}
	else {
	    var replybutton = $("#reply-" + data.postId + " .vote-" + (data.direction > 0 ? "up" : "down"));
	    var replynumber = $("#reply-" + data.postId + " strong");
	    $("#reply-" + data.postId + ".vote-button a").removeClass("selected");
	    replybutton.addClass("selected");
	    replynumber.text(data.voteCount);
	}
}

function vote(postId, direction) {
	var intDirection = (direction == "up") ? 1 : -1;
	$.post(
		"/forum/vote",
		{ postId: postId, direction: intDirection },
		VoteSuccess,
		"json"
	);
	return false;
}
function AnswerSuccess(postId){
    $("#mrkanswer-" + postId).text("You Marked This Post As Answer, Thank You");
}
function MarkAnswer(postId) {
    $.post(
		"/forum/markanswer",
		{ postId: postId },
		AnswerSuccess(postId),
		"json"
	);
    return false;
}
